package com.cyh.pangu.offer;

public class Offer42 {
    public int maxSubArray(int[] nums) {
        int res = nums[0];
        for (int i = 1; i < nums.length; i++) {
            nums[i] += Math.max(nums[i-1], 0);
            res = Math.max(res, nums[i]);
        }
        return res;
    }

    public static void main(String[] args) {
//        int[] nums = {-2,1,-3,4,-1,2,1,-5,4};
        int[] nums = {-2, -1, -5};
        Offer42 offer42 = new Offer42();
        int total = offer42.maxSubArray(nums);
        System.out.println("total:" + total);
    }
}
